<template>
  <div class="forbidden-page">
    <div class="error-container">
      <h1>403</h1>
      <h2>访问被拒绝</h2>
      <p>很抱歉，您没有权限访问此页面</p>
      <div class="button-group">
        <el-button type="primary" @click="goHome">返回首页</el-button>
        <el-button v-if="!isLoggedIn" type="default" @click="goLogin">重新登录</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { useRouter } from 'vue-router';
import { useUserStore } from '@/stores/user';
import { computed } from 'vue';

export default {
  setup() {
    const router = useRouter();
    const userStore = useUserStore();
    
    const isLoggedIn = computed(() => userStore.isLoggedIn);
    
    const goHome = () => {
      // 检查登录状态
      if (!userStore.isLoggedIn) {
        // 如果未登录，跳转到登录页
        router.push('/login');
      } else {
        // 如果已登录，跳转到首页
        router.push('/');
      }
    };
    
    const goLogin = () => {
      // 清除可能的无效登录状态
      userStore.logout();
      router.push('/login');
    };
    
    return {
      isLoggedIn,
      goHome,
      goLogin
    };
  }
};
</script>

<style scoped>
.forbidden-page {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  min-height: 500px;
  text-align: center;
}

.error-container {
  max-width: 500px;
  padding: 30px;
}

h1 {
  font-size: 100px;
  margin: 0;
  color: #F56C6C;
}

h2 {
  font-size: 32px;
  margin: 20px 0;
  color: #606266;
}

p {
  font-size: 18px;
  color: #909399;
  margin-bottom: 30px;
}

.button-group {
  display: flex;
  gap: 15px;
  justify-content: center;
}
</style>
